<html>
<head>
<title>NES ASM - Day 11</title>
</head>
<body bgcolor="lavender">
<h1 align="center" style="color: LightCoral; width: 100%; filter:shadow()">Day 11 - The JSR Instruction</h1>
<pre>


</pre>
<h2 align="center" style="color: LightCoral;"><b>JSR?</b></h2>
<p style="color: green;"><pre><b>
	
	JSR stands for Jump to SubRoutine and is used to, well... jump to a subroutine.

<h3 align="center" style="color: LightCoral;"><b>How do we use it?</b></h3>

	We use it by giving it the name of the label that we want to jump to.
Example:

	jsr OurSub
	; blah, some code

OurSub:
	; blah, some more code
	; return to instruction <i>after</i> the JSR.

<h2 align="center" style="color: LightCoral;"><b>Return? How?</b></h2>

	With the RTS (ReTurn from Subroutine) instruction of course! So the full
version of the above stuff is:

	jsr OurSub
	; blah, some code

OurSub:
	; blah, some code
	rts  ; returns and resumes execution at the first "blah, some code".

<h2 align="center" style="color: LightCoral;"><b>Something more</b></h2>

	One thing to remember though, if you just want to separate your code out.
then what is described above should be enough. If you want to jump to a subroutine based
on a comparison, you would have to do something like the following:

	cmp #5  ; compare A with 5
	bne DONTcall ; if A isn't 5 we branch over the subroutine call.
	jsr OurSub
DONTcall:



	;somewhere... possibly far away:
OurSub:

	;blah, code.
	rts ; return

<h3 align="center" style="color: LightCoral;"><b>This Day In Review</b></h3>

	I hope you get that, if you don't.. well.. I just won't think like that. ;)
Seriously though, if you ever need help with something from these tutorials or find
an error, don't hesitate to <a href="/cdn-cgi/l/email-protection#9ee8fcf0fbeaeeecf1f9ecfff3fbecdef6f1eaf3fff7f2b0fdf1f3">tell me</a>.
	
	Happy coding!,
		-Mike H a.k.a GbaGuy

<center><a href="nesasm.htm">Intro</a> - <a href="day12n.htm">Day 12</a></center>


</b></pre></p>

<br />
<br />

</body>
</html>
